<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>外卖平台登录注册</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: 
                radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3), transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3), transparent 50%),
                radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.3), transparent 50%),
                linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }
        
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="white" opacity="0.1"/><circle cx="10" cy="60" r="0.5" fill="white" opacity="0.1"/><circle cx="90" cy="40" r="0.5" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
            pointer-events: none;
        }
        
        .auth-container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 20px;
            box-shadow: 
                0 25px 50px rgba(0,0,0,0.15),
                0 0 0 1px rgba(255, 255, 255, 0.1);
            overflow: hidden;
            width: 100%;
            max-width: 450px;
            position: relative;
            z-index: 1;
        }
        
        .auth-header {
            background: linear-gradient(135deg, #ff6b6b, #ee5a24, #ff9a9e);
            color: white;
            padding: 40px 30px;
            text-align: center;
            position: relative;
            overflow: hidden;
        }
        
        .auth-header::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: float 6s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }
        
        .auth-header h1 {
            font-size: 32px;
            margin-bottom: 15px;
            position: relative;
            z-index: 2;
            text-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        
        .auth-header p {
            opacity: 0.95;
            font-size: 16px;
            position: relative;
            z-index: 2;
            text-shadow: 0 1px 2px rgba(0,0,0,0.1);
        }
        
        .auth-tabs {
            display: flex;
            background: #f8f9fa;
        }
        
        .tab-btn {
            flex: 1;
            padding: 15px;
            border: none;
            background: none;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            color: #666;
            transition: all 0.3s ease;
        }
        
        .tab-btn.active {
            background: white;
            color: #ff6b6b;
            border-bottom: 3px solid #ff6b6b;
        }
        
        .auth-content {
            padding: 30px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 600;
        }
        
        .form-group input {
            width: 100%;
            padding: 15px 20px;
            border: 2px solid #e1e5e9;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
        }
        
        .form-group input:focus {
            outline: none;
            border-color: #ff6b6b;
            background: rgba(255, 255, 255, 0.95);
            box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
            transform: translateY(-2px);
        }
        
        .btn {
            width: 100%;
            padding: 16px;
            background: linear-gradient(135deg, #ff6b6b, #ee5a24, #ff9a9e);
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
        }
        
        .btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
            transition: left 0.5s;
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
        }
        
        .btn:hover::before {
            left: 100%;
        }
        
        .btn:active {
            transform: translateY(-1px);
        }
        
        .message {
            padding: 12px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-weight: 500;
        }
        
        .message.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .message.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .hidden {
            display: none;
        }
        
        .user-type-selector {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        
        .user-type-btn {
            flex: 1;
            padding: 15px 10px;
            border: 2px solid #e1e5e9;
            border-radius: 12px;
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
            cursor: pointer;
            text-align: center;
            font-weight: 600;
            color: #666;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .user-type-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, #ff6b6b, #ee5a24);
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        .user-type-btn.active {
            border-color: #ff6b6b;
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
        }
        
        .user-type-btn.active::before {
            opacity: 1;
        }
        
        .user-type-btn span {
            position: relative;
            z-index: 2;
        }
    </style>
</head>
<body>
    <div class="auth-container">
        <div class="auth-header">
            <h1><i class="fas fa-utensils"></i> 外卖平台</h1>
            <p>专业的餐饮配送服务平台</p>
        </div>
        
        <div class="auth-tabs">
            <button class="tab-btn active" onclick="showLogin()">登录</button>
            <button class="tab-btn" onclick="showRegister()">注册</button>
        </div>
        
        <div class="auth-content">
            <!-- 登录表单 -->
            <div id="loginForm">
                <div class="user-type-selector">
                    <div class="user-type-btn active" data-type="user" onclick="selectUserType('user')">
                        <span><i class="fas fa-user"></i> 用户</span>
                    </div>
                    <div class="user-type-btn" data-type="merchant" onclick="selectUserType('merchant')">
                        <span><i class="fas fa-store"></i> 商家</span>
                    </div>
                    <div class="user-type-btn" data-type="rider" onclick="selectUserType('rider')">
                        <span><i class="fas fa-motorcycle"></i> 骑手</span>
                    </div>
                </div>
                
                <form onsubmit="handleLogin(event)">
                    <div class="form-group">
                        <label>用户名</label>
                        <input type="text" id="loginUsername" required>
                    </div>
                    <div class="form-group">
                        <label>密码</label>
                        <input type="password" id="loginPassword" required>
                    </div>
                    <button type="submit" class="btn">登录</button>
                </form>
            </div>
            
            <!-- 注册表单 -->
            <div id="registerForm" class="hidden">
                <div class="user-type-selector">
                    <div class="user-type-btn active" data-type="user" onclick="selectUserType('user')">
                        <span><i class="fas fa-user"></i> 用户</span>
                    </div>
                    <div class="user-type-btn" data-type="merchant" onclick="selectUserType('merchant')">
                        <span><i class="fas fa-store"></i> 商家</span>
                    </div>
                    <div class="user-type-btn" data-type="rider" onclick="selectUserType('rider')">
                        <span><i class="fas fa-motorcycle"></i> 骑手</span>
                    </div>
                </div>
                
                <form onsubmit="handleRegister(event)">
                    <div class="form-group">
                        <label>用户名</label>
                        <input type="text" id="regUsername" required>
                    </div>
                    <div class="form-group">
                        <label>密码</label>
                        <input type="password" id="regPassword" required>
                    </div>
                    <div class="form-group">
                        <label>手机号</label>
                        <input type="text" id="regPhone" required>
                    </div>
                    <div class="form-group">
                        <label>邮箱</label>
                        <input type="email" id="regEmail" required>
                    </div>
                    <button type="submit" class="btn">注册</button>
                </form>
            </div>
            
            <div id="message"></div>
            
            <!-- 已登录用户跳转按钮 -->
            <div id="loggedInUser" class="hidden" style="text-align: center; margin-top: 20px;">
                <p>您已登录为: <span id="loggedInUserName"></span></p>
                <button class="btn" onclick="goToMainPage()" style="margin-top: 10px;">进入主页面</button>
                <button class="btn" onclick="logout()" style="background: #6c757d; margin-top: 10px; margin-left: 10px;">退出登录</button>
            </div>
        </div>
    </div>

    <script>
        // 简单的用户数据存储
        let users = JSON.parse(localStorage.getItem('users') || '[]');
        let currentUser = null;
        let currentUserType = 'user';
        
        // 初始化一些测试用户
        if (users.length === 0) {
            users = [
                { id: 1, username: 'admin', password: '123456', phone: '13800138000', email: 'admin@test.com', type: 'user', name: '管理员' },
                { id: 2, username: 'merchant1', password: '123456', phone: '13800138001', email: 'merchant@test.com', type: 'merchant', name: '测试商家' },
                { id: 3, username: 'rider1', password: '123456', phone: '13800138002', email: 'rider@test.com', type: 'rider', name: '测试骑手' }
            ];
            localStorage.setItem('users', JSON.stringify(users));
        }
        
        function showMessage(text, type) {
            const messageDiv = document.getElementById('message');
            messageDiv.innerHTML = `<div class="message ${type}">${text}</div>`;
            setTimeout(() => {
                messageDiv.innerHTML = '';
            }, 3000);
        }
        
        function showLogin() {
            document.getElementById('loginForm').classList.remove('hidden');
            document.getElementById('registerForm').classList.add('hidden');
            document.querySelectorAll('.tab-btn')[0].classList.add('active');
            document.querySelectorAll('.tab-btn')[1].classList.remove('active');
            
            // 重置登录表单的用户类型选择器
            document.getElementById('loginForm').querySelectorAll('.user-type-btn').forEach(btn => {
                btn.classList.remove('active');
            });
            document.getElementById('loginForm').querySelector('[data-type="user"]').classList.add('active');
            currentUserType = 'user';
        }
        
        function showRegister() {
            document.getElementById('loginForm').classList.add('hidden');
            document.getElementById('registerForm').classList.remove('hidden');
            document.querySelectorAll('.tab-btn')[0].classList.remove('active');
            document.querySelectorAll('.tab-btn')[1].classList.add('active');
            
            // 重置注册表单的用户类型选择器
            document.getElementById('registerForm').querySelectorAll('.user-type-btn').forEach(btn => {
                btn.classList.remove('active');
            });
            document.getElementById('registerForm').querySelector('[data-type="user"]').classList.add('active');
            currentUserType = 'user';
        }
        
        function selectUserType(type) {
            currentUserType = type;
            // 只更新当前可见表单的用户类型选择器
            const activeForm = document.getElementById('loginForm').classList.contains('hidden') ? 
                document.getElementById('registerForm') : document.getElementById('loginForm');
            
            activeForm.querySelectorAll('.user-type-btn').forEach(btn => {
                btn.classList.remove('active');
            });
            activeForm.querySelector(`[data-type="${type}"]`).classList.add('active');
        }
        
        function handleLogin(event) {
            event.preventDefault();
            
            const username = document.getElementById('loginUsername').value;
            const password = document.getElementById('loginPassword').value;
            
            // 查找用户
            const user = users.find(u => u.username === username && u.password === password && u.type === currentUserType);
            
            if (user) {
                currentUser = user;
                localStorage.setItem('currentUser', JSON.stringify(user));
                showMessage('登录成功！正在跳转...', 'success');
                
                setTimeout(() => {
                    // 根据用户类型跳转
                    if (currentUserType === 'user') {
                        window.location.href = 'simple-index.html#user';
                    } else if (currentUserType === 'merchant') {
                        window.location.href = 'simple-index.html#merchant';
                    } else if (currentUserType === 'rider') {
                        window.location.href = 'simple-index.html#rider';
                    }
                }, 1000);
            } else {
                showMessage('用户名或密码错误！', 'error');
            }
        }
        
        function handleRegister(event) {
            event.preventDefault();
            
            const username = document.getElementById('regUsername').value;
            const password = document.getElementById('regPassword').value;
            const phone = document.getElementById('regPhone').value;
            const email = document.getElementById('regEmail').value;
            
            console.log('注册信息:', {
                username, password, phone, email, type: currentUserType
            });
            
            // 检查用户名是否已存在
            const existingUser = users.find(u => u.username === username);
            if (existingUser) {
                showMessage('用户名已存在！', 'error');
                return;
            }
            
            // 创建新用户
            const newUser = {
                id: users.length > 0 ? Math.max(...users.map(u => u.id)) + 1 : 1,
                username: username,
                password: password,
                phone: phone,
                email: email,
                type: currentUserType,
                name: username,
                registerTime: new Date().toLocaleString()
            };
            
            users.push(newUser);
            localStorage.setItem('users', JSON.stringify(users));
            
            showMessage('注册成功！请登录', 'success');
            
            // 清空注册表单
            document.getElementById('regUsername').value = '';
            document.getElementById('regPassword').value = '';
            document.getElementById('regPhone').value = '';
            document.getElementById('regEmail').value = '';
            
            // 切换到登录页面
            setTimeout(() => {
                showLogin();
            }, 1500);
        }
        
        // 页面加载时检查是否已登录
        window.onload = function() {
            const savedUser = localStorage.getItem('currentUser');
            if (savedUser) {
                currentUser = JSON.parse(savedUser);
                showLoggedInUser();
            }
        };
        
        function showLoggedInUser() {
            if (currentUser) {
                document.getElementById('loggedInUserName').textContent = currentUser.name || currentUser.username;
                document.getElementById('loggedInUser').classList.remove('hidden');
                // 隐藏登录注册表单
                document.getElementById('loginForm').classList.add('hidden');
                document.getElementById('registerForm').classList.add('hidden');
                document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
            }
        }
        
        function goToMainPage() {
            if (currentUser) {
                if (currentUser.type === 'user') {
                    window.location.href = 'simple-index.html#user';
                } else if (currentUser.type === 'merchant') {
                    window.location.href = 'simple-index.html#merchant';
                } else if (currentUser.type === 'rider') {
                    window.location.href = 'simple-index.html#rider';
                }
            }
        }
        
        function logout() {
            localStorage.removeItem('currentUser');
            currentUser = null;
            document.getElementById('loggedInUser').classList.add('hidden');
            document.getElementById('loginForm').classList.remove('hidden');
            document.querySelectorAll('.tab-btn')[0].classList.add('active');
            showMessage('已退出登录', 'success');
        }
    </script>
</body>
</html>
